import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:lx_widgets_library/lx_widgets_library.dart';

class LxToast {
  // Toast
  static show(
    String msg, {
    LxFontWeightEnum? fontWeight,
    Alignment? alignment,
    Duration? displayTime,
    SmartToastType? displayType,
    double? radius,
  }) {
    _showCustom(
      msg,
      fontWeight: fontWeight,
      alignment: alignment,
      displayTime: displayTime,
      displayType: displayType,
      radius: radius,
    );
  }

  // 自定义 builder
  static _showCustom(
    String msg, {
    LxFontWeightEnum? fontWeight,
    Alignment? alignment,
    Duration? displayTime,
    SmartToastType? displayType,
    double? radius,
  }) {
    bool isSystem = radius == null;
    SmartDialog.showToast(
      msg,
      displayTime: displayTime ?? const Duration(milliseconds: 1500),
      displayType: displayType ?? SmartToastType.last,
      alignment: alignment ?? Alignment.center,
      builder: (context) => ClipRRect(
        borderRadius: BorderRadius.all(Radius.circular(radius ?? 100)),
        child: ConstrainedBox(
          constraints: BoxConstraints(
            minWidth: 100.w,
            maxWidth: 320.w,
          ),
          child: Container(
            padding: EdgeInsets.only(
              top: isSystem ? 2 * CONTENT_MARGIN / 3 : CONTENT_MARGIN / 2,
              bottom: isSystem ? 2 * CONTENT_MARGIN / 3 : CONTENT_MARGIN / 2,
              right: CONTENT_MARGIN,
              left: CONTENT_MARGIN,
            ),
            color: Colors.black,
            child: LxText(
              msg,
              fontWeightEnum: fontWeight ?? LxFontWeightEnum.bodyLarge,
              textAlign: TextAlign.center,
            ),
          ),
        ),
      ),
    );
  }
}
